// ===============================================
// user_entity
//
// Create by Will on 9/3/2024 12:41
// Copyright @polynesia.All rights reserved.
// ===============================================

import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';

import 'dic_entity.dart';
import 'grade_entity.dart';

/// This allows the `UserEntity` class to access private members in
/// the generated file. The value for this is *.g.dart, where
/// the star denotes the source file name.
part 'user_entity.g.dart';

/// An annotation for the code generator to know that this class needs the
/// JSON serialization logic to be generated.
@JsonSerializable(genericArgumentFactories: true)
class UserEntity {
  const UserEntity({
    this.id,
    this.username,
    this.avatar,
    this.phone,
    this.email,
    this.countryCode,
    this.signature,
    this.sex,
    this.vip,
    this.vipExpireAt,
    this.disabled,
    this.wallet,
    this.inviteCode,
    this.grade,
    this.fans,
    this.follows,
    this.likeNum,
    this.exp,
    this.isFollow,
    this.follow,
    this.country,
    this.province,
    this.city,
    this.labels,
    this.sexualOrientation,
    this.friendshipIntention,
    this.age,
    this.createAt,
    this.birthday,
    this.videos,
    this.percent,
    this.videoLine,
  });

  /// A necessary factory constructor for creating a new UserEntity instance
  /// from a map. Pass the map to the generated `_$UserEntityFromJson()` constructor.
  /// The constructor is named after the source class, in this case, UserEntity.
  factory UserEntity.fromJson(Map<String, dynamic> json) =>
      _$UserEntityFromJson(json);

  final int? id;
  final String? username;
  final String? avatar;
  final String? phone;
  final String? email;
  @JsonKey(name: 'country_code')
  final String? countryCode;
  final String? signature;
  final int? sex;
  final bool? vip;
  @JsonKey(name: 'vip_expire_at')
  final String? vipExpireAt;
  final bool? disabled;
  final int? wallet;
  @JsonKey(name: 'invite_code')
  final String? inviteCode;
  final GradeEntity? grade;
  final int? fans;
  final int? follows;
  @JsonKey(name: 'like_num')
  final int? likeNum;
  final int? exp;
  @JsonKey(name: 'is_follow')
  final bool? isFollow;
  final bool? follow;
  final String? country;
  final String? province;
  final String? city;
  final List<DicEntity>? labels;
  @JsonKey(name: 'sexual_orientation')
  final String? sexualOrientation;
  @JsonKey(name: 'friendship_intention')
  final String? friendshipIntention;
  final int? age;
  @JsonKey(name: 'create_at')
  final int? createAt;
  final String? birthday;
  final int? videos;
  final num? percent;
  final String? videoLine;

  /// `toJson` is the convention for a class to declare support for serialization
  /// to JSON. The implementation simply calls the private, generated
  /// helper method `_$UserEntityToJson`.
  Map<String, dynamic> toJson() => _$UserEntityToJson(this);

  bool isEmpty() {
    const UserEntity entity = UserEntity();
    // if (entity.toString() == toString()) {
    //   return true;
    // }
    return jsonEncode(entity) == jsonEncode(this);
  }
}
